﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Domain.Customers
{
    public static class CustomerExtensions
    {
        #region Customer role

        /// <summary>
        /// 判断是否为当前权限
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="customerRoleSystem"></param>
        /// <param name="onlyActiveCustomerRoles"></param>
        /// <returns></returns>
        public static bool IsInCustomerRole(this Customer customer,
           string customerRoleSystem, bool onlyActiveCustomerRoles = true)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            return ((customer.CustomerRole.Active || !onlyActiveCustomerRoles) && customer.CustomerRole.SysRole == customerRoleSystem);

        }

        /// <summary>
        /// 是否注册用户
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="onlyActiveCustomerRoles">仅限激活权限</param>
        /// <returns></returns>
        public static bool IsRegistered(this Customer customer, bool onlyActiveCustomerRoles = true)
        {
            return IsInCustomerRole(customer, SystemRole.Registered, onlyActiveCustomerRoles);
        }

        /// <summary>
        /// 判断是否为系统用户
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="onlyActiveCustomerRoles"></param>
        /// <returns></returns>
        public static bool IsAdmin(this Customer customer, bool onlyActiveCustomerRoles = true)
        {
            return IsInCustomerRole(customer, SystemRole.Administrators, onlyActiveCustomerRoles);
        }


        /// <summary>
        /// 判断是否为匿名用户
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="onlyActiveCustomerRoles"></param>
        /// <returns></returns>
        public static bool IsGuest(this Customer customer, bool onlyActiveCustomerRoles = true)
        {
            return IsInCustomerRole(customer, SystemRole.Guests, onlyActiveCustomerRoles);
        }
        #endregion
    }
}
